package sort;

public class QuickSortTry {
	private long[] numberList;

	public long[] sort(long[] numberList) {

		// if list is 1 or smaller it is sorted
		if (numberList == null || numberList.length == 0) {
			return numberList;
		} else
			this.numberList = numberList;
		quicksort(0, numberList.length - 1);
		return this.numberList;
	}

	public int calculatePivot(long[] numberList, int from, int to) {
		long first = numberList[from];
		long last = numberList[to];
		long center = numberList[(int) ((last - first) / 2)];

		return 0;
	}

	// quicksort over a section of the list
	public void quicksort(int first, int last) {
		int left = first;
		int right = last;
		long pivot = numberList[(int) ((last - first) / 2)];

		while (first <= last) {
			// left to right
			// look for a number bigger than the pivot
			while (numberList[first] < pivot) {
				first++;
			}
			// right to left
			// look for a number smaller than the pivot
			while (numberList[last] > pivot) {
				last--;
			}
			// exchange
			if (first <= last) {
				// exchange numbers which are positioned wrong
				exchange(first, last);
				// next position
				first++;
				last--;
			}
		}
		// if "list" is bigger than 1
		// use quicksort on it
		if (left < last)
			quicksort(left, last);
		if (right > first)
			quicksort(first, right);
	}

	public void quicksort(long[] list) {
		long pivot = list[(int) (list.length / 2)];

		for (int i = 0; i < list.length; i++) {
			if (list[i] < pivot) {

			}
		}
	}

	public void exchange(int low, int high) {
		long temporary = numberList[low];
		numberList[low] = numberList[high];
		numberList[high] = temporary;
	}
}
